import { fileURLToPath, URL } from 'node:url'
import prismjs from 'vite-plugin-prismjs'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// https://vitejs.dev/config/
export default defineConfig({
    server: {
        cors: true,
        host: '127.0.0.1',
        proxy: {
            '/api': {
                target: 'http://127.0.0.1:8080',
                // target: 'http://47.109.57.7:8080',
                secure: false,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            },
            '/ws': {
                // target: 'ws://127.0.0.1:8080/',
                target: 'http://47.109.57.7:8080',
                secure: false,
                changeOrigin: true
            }
        }
    },
    plugins: [
        vue(),
        vueJsx(),
        prismjs({
            languages: [
                'json',
                'cpp',
                'python',
                'shell',
                'go',
                'js',
                'java',
                'ruby',
                'php',
                'rust',
                'vb',
                'csharp',
                'Kotlin',
                'Lua',
                'julia',
                'Haskell',
                'OCaml',
                'scala',
                'perl'
            ]
        }),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    optimizeDeps: {
        include: [
            `monaco-editor/esm/vs/language/json/json.worker`,
            `monaco-editor/esm/vs/language/css/css.worker`,
            `monaco-editor/esm/vs/language/html/html.worker`,
            `monaco-editor/esm/vs/language/typescript/ts.worker`,
            `monaco-editor/esm/vs/editor/editor.worker`
        ]
    },
    build: {
        rollupOptions: {
            output: {
                format: 'es',
                globals: {
                    vue: 'Vue'
                },
                manualChunks: {
                    'monaco-editor': ['monaco-editor']
                }
            }
        }
    }
})
